function [v_eg,eg,eg1,eg2] = refine_me(tri)
% function [v_eg,eg,eg1,eg2] = refine_me(tri)
% the edge eg is splited into eg1 and eg2,
% v_eg is new added node which is the center of edge eg.
% split the element tri into two halfs
global V T E posV posT posE TE ET;
% the first element must have the longest side 
long_idx = find_long(V(T(tri,1:3),1:2));  
% and local index for v2 and v3
v2_idx = mod(long_idx,3)+1;
v3_idx = mod(v2_idx,3)+1;
% global index for v1,v2,v3
v1 = T(tri,long_idx);
v2 = T(tri,v2_idx);
v3 = T(tri,v3_idx);
% add new node
posV = posV + 1;
V(posV,:) = (V(v2,:)+V(v3,:))/2;
% collect global index informations for v and eg to call refine_nei_green
    v_eg = posV; eg = TE(tri,long_idx);
    % add new element to T, which split tri to two elements
    tri1 = posT + 1; tri2 = posT + 2;
    T(tri1,:) = [v1,v2,v_eg];
    T(tri2,:) = [v1,v_eg,v3]; 
    posT = posT + 2;
    % add two new Edges to E , node global index from low to high
    eg1 = posE + 1; eg2 = posE + 2; eg3 = posE + 3;
    E(eg1,:) = [v2,v_eg]; 
    E(eg2,:) = [v3,v_eg];
    E(eg3,:) = [v1,v_eg];
    posE = posE + 3;
    % update matrix TE,TV,EV, actually ,TV and EV are not use now,
    TE(tri1,:) = [eg1,eg3,TE(tri,v3_idx)];
    TE(tri2,:) = [eg2,TE(tri,v2_idx),eg3];
    % only set the father of new edges 1 and 2, because the mother can be set in
    % refine_nei_green, new edge 3 can be full information
    ET(eg1,1) = tri1; 
    ET(eg2,1) = tri2;
    ET(eg3,:) = [tri1,tri2];
    % Important: the information of nei 2 and nei 3
    nei2_eg = TE(tri,v2_idx);
    tri_pos = find((ET(nei2_eg,:)-tri)==0); % 1 or 2
    ET(nei2_eg,tri_pos) = tri2; % change tri to tri2
    nei3_eg = TE(tri,v3_idx);
    tri_pos = find((ET(nei3_eg,:)-tri)==0); % 1 or 2
    ET(nei3_eg,tri_pos) = tri1; % change tri to tri1